-- 万兽魔谱
--#include "data\config\activityconfig\DailyActivity\WanShouMoPuConfig.lua" once

function WanShouMoPuDataReq(sysarg)
	local var = Actor.getStaticVar(sysarg)
	if not var.days then
		var.days = {}
	end

	local nCurIndex = var.days.wsmpIndex or 1
	WanShouMoPuSendData(sysarg, nCurIndex)
end

function WanShouMoPuAwardGet(sysarg, packet)
	--local sVar = System.getStaticVar()
	--if not sVar.WanShouFlag then
	--	Actor.sendTipmsg(sysarg, Lang.ScriptTips.WanShouMoPu003, ttFlyTip)
	--	return
	--end

	local index = DataPack.readByte(packet)

	local var = Actor.getStaticVar(sysarg)
	if not var.days then
		var.days = {}
	end

	local nCurIndex = var.days.wsmpIndex or 1
	if index ~= nCurIndex then
		return
	end

	if index > #WanShouMoPuConfig then
		return
	end

	local config = WanShouMoPuConfig[index]

	if not Actor.checkActorLevel(sysarg, config.level[2], config.level[1]) then
		Actor.sendTipmsg(sysarg, Lang.ScriptTips.WanShouMoPu004, ttFlyTip)
		return
	end

	local award = config.award
	if not Awards.CheckBagGridCount(sysarg, award) then
		return
	end

	local consume = config.consume
	if not CheckConsumeCond(sysarg, consume) then
		return 
	end

	DoConsumeCond(sysarg, consume, 1, LogIds.WanShouMoPuLogId, Lang.ScriptTips.WanShouMoPu001)	
	Awards.GiveNoCheck(sysarg, award, LogIds.WanShouMoPuLogId, Lang.ScriptTips.WanShouMoPu002)

	nCurIndex = nCurIndex + 1
	var.days.wsmpIndex = nCurIndex
	WanShouMoPuSendData(sysarg, nCurIndex)

	Actor.triggerQuestEvent(sysarg, 45, 5, nCurIndex, false)
	Actor.triggerAchieveEvent(sysarg, 44, 8)
end

function WanShouMoPuSendData(sysarg, index)
    local npack = DataPack.allocPacket(sysarg, LogicCmd.activitySys.sysId, LogicCmd.activitySys.sub.sWanShouMoPuDataRet) 
    if not npack then return end
	DataPack.writeByte(npack, index)
	DataPack.flush(npack)
end





